<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>音乐盒子</title>
    <script src="https://cdn.bootcss.com/vue/2.6.10/vue.js"></script>
    <script src="https://cdn.bootcss.com/axios/0.19.0-beta.1/axios.js"></script>
    <link rel="stylesheet" href="css/index.css">
    <!-- <link rel="stylesheet" href="css/test.css"> -->
    <link rel="icon" type="image/png" href="https://s1.music.126.net/style/favicon.ico?v20180823" sizes="32x32">
</head>

<body>
    <canvas id="canvas" ></canvas>
    <div id="app">
        <input type="text" v-model="keyword"> <button @click="handleClick">搜索音乐</button>
        <img src="images/music.jpg" alt="">
        <h4>{{keyword}}</h4>
        <audio :src="musicUrl" controls  loop autoplay>
        </audio>
    </div>

    <script>
        new Vue({
            el: "#app",
            data: {
                keyword: "成都",
                id: "",
                musicUrl: "https://music.163.com/song/media/outer/url?id=436514312",
                isPlaying: true
            },
            methods: {
                handleClick() {
                    var keyword = this.keyword;
                    axios.get(`https://music.aityp.com/search?keywords=${keyword}&limit=1`).then(res => {
                        if (res.data.code == 200) {
                            console.log(res)
                            var id = res.data.result.songs[0].id;
                            this.id = id
                            var musicUrl = `https://music.163.com/song/media/outer/url?id=${id}`
                            this.musicUrl = musicUrl;
                        } else {
                            alert("没有这首歌")
                        }

                    })
                }
            }
        })
    </script>
    <script src="js/animate.js"></script>
</body>

</html>